package test;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;



public class Lx9_4 implements ActionListener{
	
	JFrame f;
	JPanel p;
	JTextField text1;
	JLabel j;
	JButton b1,b2;
	public Lx9_4(){
		f=new JFrame("Lx9_4按钮转换文字");
		p=new JPanel();
		j=new JLabel("Lx9_4习题演示");
		p.setLayout(new GridLayout(1,2));
		text1=new JTextField(30);
		b1=new JButton("文本一");
		b2=new JButton("文本二");
		b1.setActionCommand("t1");
		b2.setActionCommand("t2");
		b1.addActionListener(this);
		b2.addActionListener(this);
		p.add(b1);
		p.add(b2);
		f.getContentPane().add(text1,BorderLayout.NORTH);
		f.getContentPane().add(p,BorderLayout.CENTER);
		f.getContentPane().add(j,BorderLayout.SOUTH);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.pack();
		f.setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("t1"))
		{
			text1.setText("Hello Java!");
		}
		else if(e.getActionCommand().equals("t2"))
		{
			text1.setText("你好  Java!");
		}
	}
	
	public static void main(String[] args) {
		Lx9_4 l=new Lx9_4();
	}
	
}